<script language="javascript">
	$(document).ready(function(){		
		getDatePicker('expiry_day');	
	});
	var baseUrl = '<?php echo $this->baseUrl(); ?>';
	// datepicker
	function getDatePicker(_id) {	
	$("#"+_id).datepicker({
		 showOn:'button',
		 dateFormat:"dd-mm-yy",
		 buttonImage:baseUrl+'/public/templates/member/js/calendar/images/calendar.gif',
		 buttonImageOnly:true,
		 yearRange: '2000:2020',
		 changeMonth:true,
		 changeYear:true,
		 showMonthAfterYear: true
		 //minDate:0
	   });
	 }
$(function()
{
    $('#expiry_time').timepicker({ 'timeFormat': 'H:i:s' });
});
</script>
<script type="text/javascript">
    function create_product(){       
        content = tinyMCE.get('product_advantages').getContent({format : 'raw'});
        re = /<[a-zA-Z\/][^>]*>/ig;
        content = content.replace(re," ");
        re = /&\w+;/ig;
        content = content.replace(re," ");   
        content = content.replace(/\s{2,}/," ");
        
        content2 = tinyMCE.get('product_conditions').getContent({format : 'raw'});
        re = /<[a-zA-Z\/][^>]*>/ig;
        content2 = content2.replace(re," ");
        re = /&\w+;/ig;
        content2 = content2.replace(re," ");
        content2 = content2.replace(/\s{2,}/," ");
        
        content3 = tinyMCE.get('product_content').getContent({format : 'raw'});
        re = /<[a-zA-Z\/][^>]*>/ig;
        content3 = content3.replace(re," ");
        re = /&\w+;/ig;
        content3 = content3.replace(re," ");   
        content3 = content3.replace(/\s{2,}/," ");
        //Luu gia tri plain text vao truong an. Sau khi submit ve server, lay gia tri
        //truong an ra de luu vao mot truong du lieu ban ro cua noi dung, phuc vu tim kiem
        
        document.getElementById('advantages_plaintext').value = content;
        document.getElementById('conditions_plaintext').value = content2;
        document.getElementById('content_plaintext').value = content3;
        return true;
    }
</script>
<div class="heading">
    <div class="left_heading"></div>
                                
    <div class="content_heading">
        <h3>Thêm tin voucher mới</h3>
    </div>
                                
    <div class="right_heading"></div>
</div><!-- End .heading -->

<div class="main_content">
    <form action="" method="post" enctype="multipart/form-data" onsubmit="return create_product()">
        <input type="hidden" name="advantages_plaintext" id="advantages_plaintext" />
        <input type="hidden" name="conditions_plaintext" id="conditions_plaintext" />
        <input type="hidden" name="content_plaintext" id="content_plaintext" />
        <table class="table_content">
        	<tr>
        		<td class="label"><label for="cat_id">Danh mục</label></td>
        		<td class="label2" colspan="2">
        			<select name="cat_id" id="cat_id" class="input">
        				<?php 
        					$category = new AdminDthink_Model_Category();
        					$listCategory = $category->listVoucher(27);
        					foreach($listCategory as $catValue) :
        				?>
        				<option value="<?php echo $catValue['cat_id']; ?>"><?php echo $catValue['cat_name']; ?></option>
        				<?php 
        					endforeach;
        				?>
        			</select>
        		</td>
        	</tr>
        	<tr>
        		<td class="label"><label for="area_id">Vùng miền</label></td>
        		<td class="label2" colspan="2">
        			<select name="area_id" id="area_id" class="input">
        				<?php 
        					$area = new AdminDthink_Model_Area();
        					$listArea = $area->listVoucher();
        					foreach($listArea as $areaValue) :
        				?>
        				<option value="<?php echo $areaValue['area_id']; ?>"><?php echo $areaValue['area_name']; ?></option>
        				<?php 
        					endforeach;
        				?>
        			</select>
        		</td>
        	</tr>
			<tr>
				<td class="label"><?php echo $this->formLabel('product_name', 'Tiêu đề tin voucher'); ?><span class="msg"> * </span></td>
				<td class="label2"><?php echo $this->formText('product_name', $this->productNameValue, array('id' => 'product_name', 'class' => 'input')); ?></td>
				<td><span class="msg"><?php echo $this->errorProductName; ?></span></td>
			</tr>
            <tr>
				<td class="label"><?php echo $this->formLabel('sort_name', 'Tiêu đề ngắn'); ?><span class="msg"> * </span></td>
				<td class="label2"><?php echo $this->formText('sort_name', $this->sortNameValue, array('id' => 'sort_name', 'class' => 'input')); ?></td>
				<td><span class="msg"><?php echo $this->errorSortName; ?></span></td>
			</tr>
			<tr>
				<td class="label"><?php echo $this->formLabel('product_image', 'Ảnh'); ?><span class="msg"> * </span></td>
				<td class="label2"><?php echo $this->formFile('product_image', array('id' => 'product_image', 'class' => 'input')); ?></td>
				<td><span class="msg"><?php echo $this->errorProductImage; ?></span></td>
			</tr>
			<tr>
				<td class="label"><?php echo $this->formLabel('product_link', 'Đường dẫn nguồn tin'); ?><span class="msg"> * </span></td>
				<td class="label2"><?php echo $this->formText('product_link', $this->productLinkValue, array('id' => 'product_link', 'class' => 'input')); ?></td>
				<td><span class="msg"><?php echo $this->errorProductLink; ?></span></td>
			</tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('original_price', 'Giá gốc'); ?><span class="msg"> * </span></td>
                <td class="label2"><?php echo $this->formText('original_price', $this->originalPriceValue, array('id' => 'original_price', 'class' => 'input')); ?> VNĐ</td>
                <td><span class="msg"><?php echo $this->errorOriginalPrice; ?></span></td>
            </tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('sales_price', 'Giá ưu đãi'); ?><span class="msg"> * </span></td>
                <td class="label2"><?php echo $this->formText('sales_price', $this->salesPriceValue, array('id' => 'sales_price', 'class' => 'input')); ?> VNĐ</td>
                <td><span class="msg"><?php echo $this->errorSalesPrice; ?></span></td>
            </tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('expiry_day', 'Ngày hết hạn'); ?><span class="msg"> * </span></td>
                <td class="label2">
                <?php echo $this->formText('expiry_day', $this->expiryDayValue, array('id' => 'expiry_day', 'class' => 'input', 'style' => 'width: 100px;')); ?>
                <?php echo $this->formText('expiry_time', $this->expiryTimeValue, array('id' => 'expiry_time', 'class' => 'input', 'style' => 'width: 80px;')); ?></td>
                <td><span class="msg"><?php echo $this->errorExpiryDay; ?></span></td>
            </tr>
        </table>
        
        <table class="table_content">
            <tr>
                <td class="label"><?php echo $this->formLabel('product_advantages', 'Ưu điểm sản phẩm'); ?><span class="msg"> * </span></td>
            </tr>
            <tr>
                <td><?php echo $this->formTextarea('product_advantages', $this->advantagesValue, array('id' => 'product_advantages', 'cols' => '60', 'rows' => '20')); ?></td>
                <td><span class="msg"><?php echo $this->errorAdvantages; ?></span></td>
            </tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('product_conditions', 'Điều kiện sử dụng'); ?><span class="msg"> * </span></td>
            </tr>
            <tr>
                <td><?php echo $this->formTextarea('product_conditions', $this->conditionsValue, array('id' => 'product_conditions', 'cols' => '60', 'rows' => '20')); ?></td>
                <td><span class="msg"><?php echo $this->errorConditions; ?></span></td>
            </tr>
            <tr>
                <td class="label"><?php echo $this->formLabel('product_content', 'Chi tiết sản phẩm'); ?><span class="msg"> * </span></td>
            </tr>
            <tr>
                <td><?php echo $this->formTextarea('product_content', $this->contentValue, array('id' => 'product_content', 'cols' => '60', 'rows' => '20')); ?></td>
                <td><span class="msg"><?php echo $this->errorContent; ?></span></td>
            </tr>
        </table>
        
        <table class="table_content">
			<tr>
				<td class="label">&nbsp;</td>
				<td colspan="2"><span class="msg"><?php echo $this->error; ?></span></td>
			</tr>
			<tr>
				<td class="label">&nbsp;</td>
				<td colspan="2">
					<input class="button" type="submit" name="submit" value="Tạo mới">
					<input class="button" type="reset" name="reset" value="Nhập lại">
					<a href="<?php echo $this->baseUrl('member-cp/product'); ?>" class="button" style="padding-top: 7px;">Quay lại</a>
				</td>
			</tr>
        </table>
    </form>
</div><!-- End .main_content -->  